home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fhard101.zip / VHARD.ASM < prev    next >
Assembly Source File  |  1990-07-22  |  58KB  |  2,120 lines

  1.  
  2.     title    Fake hard disk driver
  3.     subttl    Prologue
  4.     page    60,132
  5.  
  6. comment    {
  7.  
  8. ******************************************************************************
  9.  
  10. File VHARD.ASM
  11.  
  12. Author:
  13.     Aaron L. Brenner
  14.  
  15.     BIX mail address albrenner
  16.     GEnie address A.BRENNER
  17.  
  18.     This program is hereby released to the public domain.
  19.  
  20. Purpose:
  21.     A DOS device driver that will make a floppy drive double as a small
  22.     hard disk.
  23.  
  24.     This is accomplished by spreading the fake HD over a series of
  25.     diskettes. The disks must be prepared (with VHPREP) by formatting to
  26.     10 sectors/track for a capacity of 400KB per diskette. Also, VHPREP
  27.     will stamp each diskette with a unique ID built from the date and time
  28.     the first diskette was prepared and the sequence number of it. VHPREP
  29.     is also responsible for performing the low and high level format on
  30.     all disks. Formatting is performed by the driver, but under VHPREP
  31.     control.
  32.  
  33.     VHPREP communicates with the driver via a dummy character device
  34.     driver named VHARDCTL, which will provide access to driver functions.
  35.     The only driver command supported is IOCTL Write (all others are
  36.     NOPs), and only 7 bytes are actually used. These 7 bytes are treated
  37.     as a command block, structured as follows:
  38.  
  39.     Format command
  40.     byte     0
  41.     byte    track to format (head in bit 7, cylinder in low 7 bits)
  42.     byte    return status
  43.     dword    pointer to format parameter buffer (see details in int 13h)
  44.  
  45.     Read Track command
  46.     byte    1
  47.     byte    track to read (head in bit 7, cylinder in low 7 bits)
  48.     byte    return status
  49.     dword    pointer to buffer to read into
  50.  
  51.     Write Track command
  52.     byte    2
  53.     byte    track to write (head in bit 7, cylinder in low 7 bits)
  54.     byte    return status
  55.     dword    pointer to buffer to write from
  56.  
  57.     Verify Track command
  58.     byte    3
  59.     byte    track to verify (head in bit 7, cylinder in low 7 bits)
  60.     byte    return status
  61.  
  62.     Set FAT cache buffer
  63.     byte    4
  64.     byte    == 0, disable cache
  65.         == 1, enable cache
  66.         == 2, flush cache
  67.         == 3, disable cache autoflush
  68.         == 4, enable cache autoflush (DOS 3+, SHARE installed)
  69.         == 5, return information about the cache
  70.     byte    return status
  71.     dword    pointer to cache buffer
  72.     This command is used to enable or disable the FAT/directory cache.
  73.     Once the cache is enabled, logical sectors 1 through 24 will be cached
  74.     for both read and write. They will only be written when driver
  75.     function 14 (Device close) is called AND the reference count is 0.
  76.     To accomodate older versions of DOS, subcommand 2 will manually flush
  77.     the cache to disk. Subcommands 3 & 4 will disable or enable the
  78.     auto-flush.
  79.  
  80.     Retrieve Driver Data
  81.     byte    5
  82.     byte    unused
  83.     byte    set to 0 by VHARD
  84.     dword    pointer to buffer to receive the following data:
  85.         byte        drive number assigned by DOS
  86.         word        VHARD version
  87.         19 bytes    BPB for VHARD
  88.  
  89. Revision history:
  90. 0.90    06/27/90    ALB    Created. This version uses 13 360KB diskettes
  91.                 for appx. 5MB of faked hard disk space. Note:
  92.                 cache handling is NOT yet implemented.
  93.  
  94. ******************************************************************************
  95.  
  96. endcomment {
  97.  
  98.     subttl    Included files
  99.     page
  100.  
  101.     include    dd_defs.inc
  102.     include    vhard.inc        ; Some structures we use
  103.  
  104. DEBUG    equ    0
  105.  
  106.  
  107.     subttl    Macros and templates
  108.     page
  109.  
  110. BIOS_seg    segment at 40h
  111.  
  112.     org    62h
  113. active_page    db    ?
  114.  
  115.     org    84h
  116. crt_lines    db    ?
  117.  
  118. BIOS_seg    ends
  119.  
  120.  
  121. ;*****************************************************************************
  122. ;
  123. ; Version of VHARD
  124. ;
  125. ;*****************************************************************************
  126. VHARD_version    equ    100h
  127. VHARD_text_ver    equ    <'1.00'>
  128.  
  129.  
  130.     subttl    Device driver headers
  131.     page
  132.  
  133. vhard_seg    segment
  134.  
  135.     org    0
  136.  
  137. assume    cs:vhard_seg, ds:nothing, es:nothing, ss:nothing
  138.  
  139. ;
  140. ; Declare the header for the dummy char device used to communicate with
  141. ; the block driver
  142. ;
  143.         dw    offset next_hdr
  144. nextdvrseg    dw    -1
  145.         dw    DA_IS_CHAR or DA_IOCTL
  146.         dw    strategy
  147.         dw    du_int
  148.         db    'VHARDCTL'
  149.  
  150. ;
  151. ; Declare the header for the device driver
  152. ; Attributes:
  153. ;    block device
  154. ;    removable media
  155. ;
  156. next_hdr    dw    -1, -1
  157.         dw    DA_IS_BLK or DA_IS_REM
  158.         dw    strategy
  159.         dw    vh_int
  160.         db    1, 'VHARD  '
  161.  
  162.     subttl    Device driver data
  163.     page
  164.  
  165. ;
  166. ; Pointer passed by DOS to the request packet
  167. ;
  168. req_ptr        dw    0, 0
  169.  
  170. ;
  171. ; Version of DOS
  172. ;
  173. dos_ver        dw    0
  174.  
  175. ;
  176. ; Local copy of the diskette parameters
  177. ;
  178. diskparms    db    4 dup(0)    ; Gets filled in at init time
  179. sect_per_track    db    0        ; Sectors per track (set at init time)
  180. gap_len        db    0
  181.         db    0
  182. fmt_gap_len    db    0
  183.         db    3 dup(0)
  184.  
  185. ;
  186. ; Save area for old parm pointer
  187. ;
  188. old_pptr    dw    0, 0
  189.  
  190. ;
  191. ; ID and # for the current disk
  192. ;
  193. curr_disk_id    db    'NO NAME',0
  194.         db    0
  195. curr_disk_num    db    0ffh
  196.  
  197. ;
  198. ; Counter of how many sectors read/written
  199. ;
  200. io_count    dw    0
  201.  
  202. ;
  203. ; Count of how many sectors to go
  204. ;
  205. io_to_go    dw    0
  206.  
  207. ;
  208. ; Flag indicating whether or not we have EGA/VGA video available. This is used
  209. ; in the prompt_user routine - if have_evga != 0, then we read the number of
  210. ; character lines on screen from 40:84. If have_evga == 0, then we always use
  211. ; line 24.
  212. ;
  213. have_evga    db    0
  214. last_curs    dw    0
  215.  
  216. ;
  217. ; If we're running under DOS 3.10 or higher, we get the drive number assigned
  218. ; from the the request block and save it here.
  219. ;
  220. our_drive    db    0ffh
  221.  
  222. ;
  223. ; Data used to manage the FAT/dir cache.
  224. ;
  225. cache_ptr    dw    0,0        ; Pointer to the cache
  226. cache_flags    db    0        ; Bit flags
  227.  
  228. ;
  229. ; Messages that get displayed at various times
  230. ;
  231. need_disk    db    'Put disk ID '
  232. pr_disk_id    db    8 dup(' ')
  233.         db    ' #'
  234. pr_disk_num    db    '  '
  235.         db    ' in drive A:, then press a key',0
  236.  
  237. need_first_disk    db    'Put disk #0 of the set you want to use'
  238.         db    ' in drive A:, then press a key',0
  239.  
  240. ;
  241. ; Save area for the chunk of screen we diddle
  242. ;
  243. screen_save    dw    80 dup(0)
  244.  
  245. ;
  246. ; Buffer for the boot sector (containing ID, etc.)
  247. ;
  248. boot_sect_buf    db    512 dup(0)
  249.  
  250. ;*****************************************************************************
  251. ;
  252. ; These 2 tables are used to translate BIOS error codes into the status codes
  253. ; expected by DOS and VHPREP, respectively
  254. ;
  255. ;*****************************************************************************
  256. DOS_sts_table    db    80h,    DE_NOT_READY
  257.         db    40h,    DE_SEEK_ERROR
  258.         db    20h,    DE_GEN_FAIL
  259.         db    10h,    DE_CRC_ERROR
  260.         db    9,    DE_WRITE_FAULT
  261.         db    8,    DE_WRITE_FAULT
  262.         db    4,    DE_NOT_FOUND
  263.         db    3,    DE_WRITE_PROT
  264.         db    2,    DE_GEN_FAIL
  265.         db    1,    DE_GEN_FAIL
  266.  
  267. CMD_sts_table    db    80h,    STS_TIMEOUT
  268.         db    40h,    STS_BAD_SEEK
  269.         db    20h,    STS_BAD_NEC
  270.         db    10h,    STS_BAD_CRC
  271.         db    9,    STS_DMA_BOUND
  272.         db    8,    STS_BAD_DMA
  273.         db    4,    STS_NOT_FND
  274.         db    3,    STS_WRITE_PROT
  275.         db    2,    STS_ADDR_MARK
  276.         db    1,    STS_BAD_CMD
  277.  
  278.  
  279. ;*****************************************************************************
  280. ;
  281. ; BIOS parameter block (BPB) that DOS is going to use
  282. ;
  283. ;*****************************************************************************
  284. our_bpb    DOS_BPB    <512, 8, 1, 2, 256, (13 * 799), 0fch, 4, 47, 26, 0>
  285.  
  286. our_bpb_array    dw    offset our_bpb
  287.  
  288.  
  289. ;*****************************************************************************
  290. ;
  291. ; For this version, at least, this driver will support the OPEN and CLOSE
  292. ; calls. These will increment and decrement a reference counter that will be
  293. ; used to know when to the write the FAT cache (if caching is enabled).
  294. ;
  295. ;*****************************************************************************
  296. ref_count    dw    0
  297.  
  298.  
  299.     subttl    Device driver STRATEGY and INTERRUPT routines
  300.     page
  301.  
  302. ;*****************************************************************************
  303. ;
  304. ; Strategy entry point. Used for both drivers
  305. ;
  306. ;*****************************************************************************
  307. strategy    proc    far
  308.  
  309.     mov    cs:req_ptr[0],bx    ; Save the pointer
  310.     mov    cs:req_ptr[2],es    ;
  311.     ret                ; Return to DOS
  312.  
  313. strategy    endp
  314.  
  315.  
  316. ;*****************************************************************************
  317. ;
  318. ; Interrupt routine for the VH driver
  319. ;
  320. ;*****************************************************************************
  321. vh_int        proc    far
  322.  
  323. assume    ds:nothing, es:nothing
  324.  
  325.     call    save_regs        ; Save the registers
  326.     cld                ; Make sure of direction
  327.     push    cs            ; Set DS to our segment
  328.     pop    ds            ;
  329.  
  330. assume    ds:vhard_seg
  331.  
  332. if    DEBUG
  333.     call    dump_entry
  334. endif
  335.  
  336.     les    si,dword ptr req_p